/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.services.gl;

/**
 *
 * @author jay
 */

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.model.SelectItem;
import src.domain.gl.Glaccnt;
import src.services.CRUEDService;
import src.util.Constanta;

public class GlaccntModel implements java.io.Serializable {
    
    private CRUEDService service;
    
    public GlaccntModel() {
        service = new CRUEDService();
    }
    
    public List<Glaccnt> findAll(Map<String, Object> filters) {
        return (List<Glaccnt>) service.findAllSQLAdvance("from Glaccnt  as glaccnt", filters," order by glaccnt.accountNo");
    }
    
    public List<SelectItem> listAll() {
        return service.listAll("Glaccnt", "glaccntId", " concat(accountNo,' ', accountName)");
    }
    
    public String getNameById(Integer id) {
        return (String) service.getObjectSQL("select gl.accountName from Glaccnt as gl "+
                "where gl.glaccntId = "+id, null);
    }
    
    public boolean validateParent(Integer id) {
        BigDecimal count = (BigDecimal) service.getObjectSQLdirect("select count(*) from jvdet where glaccnt_Id = "+id);
        return (count.compareTo(BigDecimal.ZERO)==0 ? true : false);
    }
    
    public boolean saveData(Glaccnt data) {
        return service.saveData(data);
    }
    
    public boolean deleteData(Glaccnt data) {
        return service.deleteData(data);
    }
    
    public Glaccnt getById(Integer id) {
        Map<String, String> where = new HashMap<>();
        where.put("gl.glaccntId", id.toString());
        if (id != null) 
        {
            if (id > 0) 
                return (Glaccnt) service.getObjectSQL("from Glaccnt as gl", where);
            else return null;
            
        } else return null;
    }
    
    
    
}
